﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MsForgeReboot.Framework.Interfaces;
using MsForgeReboot.Framework.ViewModels;

namespace MsForgeReboot.Services {
    public class CarouselService : ICarouselService {
        #region ICarouselService Members

        private readonly MsForgeContext _context;

        public CarouselService(MsForgeContext c) {
            this._context = c;
        }

        public IList<Framework.ViewModels.CarouselViewModel> GetHomePageCarousel(int limit = 1) {
            //throw new NotImplementedException();
            List<CarouselViewModel> result = new List<CarouselViewModel>();
            result.AddRange(this._context.BlogPosts.
                OrderBy(b => Guid.NewGuid()).
                Select(b => new CarouselViewModel { 
                    Title = b.Title, 
                    Body = b.Body.Substring(0, 200) }).
                    Take(limit).
                    ToList()
            );
            result.AddRange(this._context.Speakers.
                OrderBy(s => Guid.NewGuid()).
                Select(s => new CarouselViewModel {
                    Title = s.FirstName + " " + s.LastName,
                    Body = (s.Biography == "") ? "" : s.Biography
                }).
                Take(limit)
            );

            return result.ToList();
        }

        #endregion
    }
}
